<template>
  <div class="parking-space-manage">
    <!-- 操作按钮区域 -->
    <el-row :gutter="8" class="operation-buttons">
      <el-col :span="1.5">
        <el-button type="primary" @click="showAddDialog">添加</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="default" @click="deleteParkingSpaces">删除</el-button>
      </el-col>
      <el-col :span="16" class="search-area">
        <el-input
          placeholder="请输入车位号"
          v-model="searchCarNo"
          style="width: 200px; margin-right: 10px;"
          suffix-icon="el-icon-search"
        ></el-input>
        <el-button type="primary" icon="el-icon-search" @click="searchParkingSpaces">搜索</el-button>
      </el-col>
    </el-row>

    <!-- 表格区域 -->
    <el-table
      :data="tableData"
      border
      style="width: 100%; margin-top: 20px;"
      @selection-change="handleSelectionChange"
      v-loading="loading"
    >
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="parkingSpaceCode" label="车位编号" width="120"></el-table-column>
      <el-table-column prop="community.communityName" label="所属小区" width="120"></el-table-column>
      <el-table-column prop="parkingSpaceCategory" label="车位类型" width="120" :formatter="formatParkingCategory"></el-table-column>
      <el-table-column prop="parkingSpaceStatus" label="车位状态" width="120" :formatter="formatParkingStatus"></el-table-column>
      <el-table-column prop="parkingSpaceArea" label="车位面积" width="120"></el-table-column>
      <el-table-column prop="parkingSpaceMoney" label="收费金额" width="120" :formatter="formatTotalPrice"></el-table-column>
      <el-table-column label="操作" width="400">
        <template slot-scope="scope">
          <el-link type="primary" :underline="false" @click="viewDetails(scope.row)">详情</el-link>
          <el-link type="primary" :underline="false" style="margin: 0 10px;" @click="bindHomeowner(scope.row)">绑定住户</el-link>
          <el-link type="primary" :underline="false" @click="bindVehicle(scope.row)">绑定车辆</el-link>
          <el-link type="primary" :underline="false" style="margin: 0 10px;" @click="addPricing(scope.row)">添加收费标准</el-link>
          <el-link type="primary" :underline="false" @click="editParkingSpace(scope.row)">编辑</el-link>
          <el-link type="primary" :underline="false" style="margin-left: 10px;" @click="deleteParkingSpace(scope.row)">删除</el-link>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页区域 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="margin-top: 20px; text-align: center;"
    ></el-pagination>

    <!-- 添加车位对话框 -->
    <el-dialog
      title="添加车位"
      :visible.sync="dialogVisible"
      width="30%"
    >
      <el-form ref="form" :model="form" label-width="150px">
        <el-form-item label="小区*" prop="community">
          <el-select v-model="form.community" placeholder="请选择小区">
            <el-option
              v-for="item in neighborhoods"
              :key="item.label"
              :label="item.value"
              :value="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车位号*" prop="parkingSpaceCode">
          <el-input v-model="form.parkingSpaceCode" placeholder="请输入车位号"></el-input>
        </el-form-item>
        <el-form-item label="产权面积*" prop="parkingSpaceArea">
          <el-input v-model.number="form.parkingSpaceArea" placeholder="请输入面积"></el-input>
          <span style="margin-left: 10px;">平方米</span>
        </el-form-item>
        <el-form-item label="车位类型*" prop="parkingSpaceCategory">
          <el-select v-model="form.parkingSpaceCategory" placeholder="请选择类型">
            <el-option label="产权车位" value="0"></el-option>
            <el-option label="公共车位" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车位状态*" prop="parkingSpaceStatus">
          <el-select v-model="form.parkingSpaceStatus" placeholder="请选择状态">
            <el-option label="空闲" value="0"></el-option>
            <el-option label="已出租" value="1"></el-option>
            <el-option label="自用" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="form.notes" type="textarea" placeholder="请输入备注"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="saveParkingSpace">保存</el-button>
      </span>
    </el-dialog>

    <!-- 详情对话框 -->
    <el-dialog title="车位详情" :visible.sync="detailDialog.visible" width="50%">
      <el-descriptions :column="2" border>
        <el-descriptions-item label="车位编号">{{ detailDialog.data.parkingSpaceCode }}</el-descriptions-item>
        <el-descriptions-item label="所属小区">{{ detailDialog.data.community?.communityName }}</el-descriptions-item>
        <el-descriptions-item label="车位类型">{{ formatParkingCategory(detailDialog.data) }}</el-descriptions-item>
        <el-descriptions-item label="车位状态">{{ formatParkingStatus(detailDialog.data) }}</el-descriptions-item>
        <el-descriptions-item label="车位面积">{{ detailDialog.data.parkingSpaceArea }} 平方米</el-descriptions-item>
        <el-descriptions-item label="收费金额">{{ formatTotalPrice(detailDialog.data) }}</el-descriptions-item>
        <el-descriptions-item label="备注" :span="2">{{ detailDialog.data.parkingSpaceDesc || '无' }}</el-descriptions-item>
      </el-descriptions>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="detailDialog.visible = false">关闭</el-button>
      </span>
    </el-dialog>

    <!-- 编辑对话框 -->
    <el-dialog title="编辑车位" :visible.sync="editDialog.visible" width="30%">
      <el-form ref="editForm" :model="editDialog.form" label-width="150px">
        <el-form-item label="小区*" prop="community">
          <el-select v-model="editDialog.form.communityId" placeholder="请选择">
            <el-option
              v-for="item in neighborhoods"
              :key="item.label"
              :label="item.value"
              :value="item.label"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车位号*" prop="parkingSpaceCode">
          <el-input v-model="editDialog.form.parkingSpaceCode" placeholder="请输入"></el-input>
        </el-form-item>
        <el-form-item label="产权面积*" prop="parkingSpaceArea">
          <el-input v-model.number="editDialog.form.parkingSpaceArea" placeholder="请输入"></el-input>
          <span style="margin-left: 10px;">平方米</span>
        </el-form-item>
        <el-form-item label="车位类型*" prop="parkingSpaceCategory">
          <el-select v-model="editDialog.form.parkingSpaceCategory" placeholder="请选择">
            <el-option label="产权车位" value="0"></el-option>
            <el-option label="公共车位" value="1"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车位状态*" prop="parkingSpaceStatus">
          <el-select v-model="editDialog.form.parkingSpaceStatus" placeholder="请选择">
            <el-option label="空闲" value="0"></el-option>
            <el-option label="已出租" value="1"></el-option>
            <el-option label="自用" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input v-model="editDialog.form.notes" type="textarea" placeholder="请输入"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialog.visible = false">取消</el-button>
        <el-button type="primary" @click="submitEdit">保存</el-button>
      </span>
    </el-dialog>

    <!-- 绑定住户对话框 -->
    <el-dialog title="绑定住户" :visible.sync="bindHomeownerDialog.visible" width="40%">
      <el-form :model="bindHomeownerDialog.form" label-width="120px">
        <el-form-item label="住户姓名">
          <el-input v-model="bindHomeownerDialog.searchName" placeholder="输入住户姓名搜索" style="width: 200px;"></el-input>
          <el-button type="primary" @click="searchHomeowners">搜索</el-button>
        </el-form-item>
        <el-form-item label="选择住户">
          <el-table :data="bindHomeownerDialog.homeownerList" border style="width: 100%" @selection-change="handleHomeownerSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="homeownerName" label="姓名" width="120"></el-table-column>
            <el-table-column prop="homeownerPhone" label="电话" width="150"></el-table-column>
            <el-table-column prop="homeownerUnit" label="单元"></el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bindHomeownerDialog.visible = false">取消</el-button>
        <el-button type="primary" @click="submitBindHomeowner">确定</el-button>
      </span>
    </el-dialog>

    <!-- 绑定车辆对话框 -->
    <el-dialog title="绑定车辆" :visible.sync="bindVehicleDialog.visible" width="40%">
      <el-form :model="bindVehicleDialog.form" label-width="120px">
        <el-form-item label="车牌号">
          <el-input v-model="bindVehicleDialog.searchPlate" placeholder="输入车牌号搜索" style="width: 200px;"></el-input>
          <el-button type="primary" @click="searchVehicles">搜索</el-button>
        </el-form-item>
        <el-form-item label="选择车辆">
          <el-table :data="bindVehicleDialog.vehicleList" border style="width: 100%" @selection-change="handleVehicleSelectionChange">
            <el-table-column type="selection" width="55"></el-table-column>
            <el-table-column prop="carPlate" label="车牌号" width="150"></el-table-column>
            <el-table-column prop="carBrand" label="品牌" width="120"></el-table-column>
            <el-table-column prop="carColor" label="颜色"></el-table-column>
          </el-table>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="bindVehicleDialog.visible = false">取消</el-button>
        <el-button type="primary" @click="submitBindVehicle">确定</el-button>
      </span>
    </el-dialog>

    <!-- 收费标准设置对话框 -->
  <el-dialog
    title="收费标准设置"
    :visible.sync="chargeStandardDialogVisible"
    width="400px"
  >
    <el-form :model="chargeStandardForm" label-width="100px">
      <el-form-item label="收费标准">
        <el-select 
          v-model="chargeStandardForm.pricingId" 
          placeholder="请选择收费标准"
          @change="handlePricingChange"
        >
          <el-option 
            v-for="item in pricingList" 
            :key="item.pricingId"
            :label="item.pricingName" 
            :value="item.pricingId"
          ></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="chargeStandardDialogVisible = false">取消</el-button>
      <el-button type="primary" @click="saveChargeStandard">确定</el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>


export default {
  name: 'ParkingSpaceManage',
  data() {
    return {
      searchCarNo: '',
      tableData: [],
      selectedRows: [],
      currentPage: 1,
      pageSize: 10,
      total: 0,
      loading: false,
      
      // 添加车位对话框
      dialogVisible: false,
      form: {
        parkingSpaceId: "",
        community: '',
        parkingSpaceCode: '',
        parkingSpaceArea: null,
        parkingSpaceCategory: '',
        parkingSpaceStatus: '',
        notes: '',
      },
      
      // 小区选项
      neighborhoods: [],
      
      // 详情对话框
      detailDialog: {
        visible: false,
        data: {}
      },
      
      // 编辑对话框
      editDialog: {
        visible: false,
        form: {
          parkingSpaceId: '',
          communityId: '',
          parkingSpaceCode: '',
          parkingSpaceArea: null,
          parkingSpaceCategory: '',
          parkingSpaceStatus: '',
          notes: '',
          homeownerId: '',
          carId: '',
          pricingId: '',
        }
      },
      
      // 绑定住户对话框
      bindHomeownerDialog: {
        visible: false,
        searchName: '',
        selectedHomeowner: null,
        homeownerList: [],
        form: {
          parkingSpaceId: '',
          homeownerId: ''
        }
      },
      
      // 绑定车辆对话框
      bindVehicleDialog: {
        visible: false,
        searchPlate: '',
        selectedVehicle: null,
        vehicleList: [],
        form: {
          parkingSpaceId: '',
          carId: ''
        }
      },

      // 收费标准设置对话框
      chargeStandardDialogVisible: false,
      chargeStandardForm: {
        pricingId: '',
        pricingName: '',
        parkingSpaceId: '', // 添加车位ID
        communityId: '', // 小区ID
      },
      pricingList: [], // 存储所有收费标准
      currentParkingSpace: null // 当前操作的车位
    };
  },
  mounted() {
    this.getParkingSpace(this.currentPage);
  },
  methods: {
    // 获取所有车位信息
    getParkingSpace(pageNum) {
      this.loading = true;
      this.$axios.post('http://localhost:8080/parkingSpace/parkingPage', {
        parkingCode: this.searchCarNo,
        pageNum: pageNum,
        pageSize: this.pageSize,
      })
      .then(resp => {
        console.log('获取车位信息:', resp);
        if (resp.data.code === 200) {
          this.tableData = resp.data.data.records || [];
          this.total = resp.data.data.total || 0;
          this.currentPage = resp.data.data.current || 1;
        } else {
          this.$message.error(resp.data.message || '获取车位信息失败');
        }
      })
      .catch(error => {
        console.error('获取车位信息失败', error);
        this.$message.error('获取车位信息失败');
      })
      .finally(() => {
        this.loading = false;
      });
    },

    // 获取所有小区
    getNeighborhoods() {
      return this.$axios.get('http://localhost:8080/community/selcomm')
      .then(resp => {
        if (resp.data.code === 200) {
          this.neighborhoods = resp.data.data.map(item => {
            return { value: item.communityName, label: item.communityId };
          });
        }
      })
      .catch(error => {
        console.error('获取小区列表失败', error);
      });
    },

    // 展示添加车位对话框
    async showAddDialog() {
      await this.getNeighborhoods();
      this.dialogVisible = true;
    },

    // 重置表单
    resetForm() {
      this.form = {
        community: '',
        parkingSpaceCode: '',
        parkingSpaceArea: null,
        parkingSpaceCategory: '',
        parkingSpaceStatus: '',
        notes: ''
      };
    },

    // 保存车位信息
    saveParkingSpace() {
      const parkingSpace = {
        parkingSpaceId: '',
        communityId: this.form.community,
        parkingSpaceCode: this.form.parkingSpaceCode,
        parkingSpaceArea: this.form.parkingSpaceArea,
        parkingSpaceCategory: this.form.parkingSpaceCategory,
        parkingSpaceStatus: this.form.parkingSpaceStatus,
        parkingSpaceDesc: this.form.notes,
        homeownerId: '',
        carId: '',
        pricingId: '',
        parkingSpaceMoney: 0,
      };

      this.$axios.post('http://localhost:8080/parkingSpace/addparking', parkingSpace)
        .then(resp => {
          if (resp.data.code === 200) {
            this.$message.success('车位添加成功');
            this.dialogVisible = false;
            this.resetForm();
            this.getParkingSpace(this.currentPage);
          } else {
            this.$message.error(resp.data.message || '车位添加失败');
          }
        })
        .catch(error => {
          console.error('保存车位信息失败', error);
          this.$message.error('保存失败，请重试');
        });
    },

    // 搜索车位信息
    searchParkingSpaces() {
      this.currentPage = 1;
      this.getParkingSpace(this.currentPage);
    },

    // 删除车位方法
    deleteParkingSpacemethod(val) {
      this.$axios.post('http://localhost:8080/parkingSpace/delparking', val)
      .then(resp => {
        if (resp.data.code === 200) {
          this.$message.success('删除成功');
          this.selectedRows = [];
          this.getParkingSpace(this.currentPage);
        } else {
          this.$message.error(resp.data.message || '删除失败');
        }
      })
      .catch(error => {
        console.error('删除车位失败', error);
        this.$message.error('删除失败，请重试');
      });
    },

    // 删除选中的车位
    deleteParkingSpaces() {
      if (this.selectedRows.length === 0) {
        this.$message.warning('请先选择要删除的车位');
        return;
      }

      this.$confirm('将删除选中的车位, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.deleteParkingSpacemethod(this.selectedRows);
      }).catch(() => {
        this.$message.info('已取消删除');
      });
    },

    // 处理表格选择变化
    handleSelectionChange(val) {
      this.selectedRows = val.map(row => row.parkingSpaceId);
    },

    // 处理分页大小变化
    handleSizeChange(val) {
      this.pageSize = val;
      this.getParkingSpace(1);
    },

    // 处理当前页变化
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getParkingSpace(this.currentPage);
    },

    // 格式化车位类型
    formatParkingCategory(row) {
      return row.parkingSpaceCategory === 0 ? '公共车位' : '产权车位';
    },

    // 格式化车位状态
    formatParkingStatus(row) {
      switch (row.parkingSpaceStatus) {
        case 0: return '出租';
        case 1: return '出售';
        case 2: return '空置';
        case 3: return '自用';
        default: return '未知状态';
      }
    },

    // 格式化收费金额
    formatTotalPrice(row) {
      return `￥${row.parkingSpaceMoney || 0}/月`;
    },

    // 查看详情
    viewDetails(row) {
      this.detailDialog.data = row;
      this.detailDialog.visible = true;
    },

    // 编辑车位
    editParkingSpace(row) {
      this.editDialog.form = {
        parkingSpaceId: row.parkingSpaceId,
        communityId: row.community?.communityId || '',
        parkingSpaceCode: row.parkingSpaceCode,
        parkingSpaceArea: row.parkingSpaceArea,
        parkingSpaceCategory: row.parkingSpaceCategory?.toString() || '0',
        parkingSpaceStatus: row.parkingSpaceStatus?.toString() || '0',
        notes: row.parkingSpaceDesc || '',
        homeownerId: row.homeownerId || '',
        carId: row.carId || '',
        pricingId: row.pricingId || '',
      };
      this.editDialog.visible = true;
    },

    // 提交编辑
    submitEdit() {
      const parkingSpace = {
        parkingSpaceId: this.editDialog.form.parkingSpaceId,
        communityId: this.editDialog.form.communityId,
        parkingSpaceCode: this.editDialog.form.parkingSpaceCode,
        parkingSpaceArea: this.editDialog.form.parkingSpaceArea,
        parkingSpaceCategory: this.editDialog.form.parkingSpaceCategory,
        parkingSpaceStatus: this.editDialog.form.parkingSpaceStatus,
        parkingSpaceDesc: this.editDialog.form.notes,
        homeownerId: this.editDialog.form.homeownerId || '',
        carId: this.editDialog.form.carId || '',
        pricingId: this.editDialog.form.pricingId || '',
        parkingSpaceMoney: 0,
      };

      console.log(this.editDialog.form);
      
      this.$axios.post('http://localhost:8080/parkingSpace/editparking', parkingSpace)
        .then(resp => {
          if (resp.data.code === 200) {
            this.$message.success('车位信息更新成功');
            this.editDialog.visible = false;
            this.getParkingSpace(this.currentPage);
          } else {
            this.$message.error(resp.data.message || '更新失败');
          }
        })
        .catch(error => {
          console.error('更新车位信息失败', error);
          this.$message.error('更新失败，请重试');
        });
    },

    // 绑定住户
    bindHomeowner(row) {
      console.log(row.parkingSpaceId);
      
      this.bindHomeownerDialog.form.parkingSpaceId = row.parkingSpaceId;
      this.bindHomeownerDialog.visible = true;
      this.searchHomeowners();
    },

    // 搜索住户
    searchHomeowners() {
      this.$axios.post('http://localhost:8080/homeowner/pageall', {
        
          title: this.bindHomeownerDialog.searchName,
          pageNum: 1,
          pageSize:100,
          liveStatus:0,
          status:0
         
      })
      .then(resp => {
        if (resp.data.code === 200) {
          this.bindHomeownerDialog.homeownerList = resp.data.data.records || [];
        }
      })
      .catch(error => {
        console.error('获取住户列表失败', error);
      });
    },

    // 处理住户选择变化
    handleHomeownerSelectionChange(val) {
      this.bindHomeownerDialog.selectedHomeowner = val.length > 0 ? val[0] : null;
    },

    // 提交绑定住户
    submitBindHomeowner() {
      if (!this.bindHomeownerDialog.selectedHomeowner) {
        this.$message.error('请选择要绑定的住户');
        return;
      }
        console.log(this.bindHomeownerDialog.form.parkingSpaceId);
        
      const params = {
        parkingId: this.bindHomeownerDialog.form.parkingSpaceId,
        homeownerId: this.bindHomeownerDialog.selectedHomeowner.homeownerId
      };

      this.$axios.put('http://localhost:8080/parkingSpace/bperson', params)
        .then(resp => {
          if (resp.data.code === 200) {
            this.$message.success('住户绑定成功');
            this.bindHomeownerDialog.visible = false;
            this.getParkingSpace(this.currentPage);
          } else {
            this.$message.error(resp.data.message || '住户绑定失败');
          }
        })
        .catch(error => {
          console.error('绑定住户失败', error);
          this.$message.error('绑定失败，请重试');
        });
    },

    // 绑定车辆
    bindVehicle(row) {
      this.bindVehicleDialog.form.parkingSpaceId = row.parkingSpaceId;
      this.bindVehicleDialog.visible = true;
      this.searchVehicles();
    },

    // 搜索车辆
    searchVehicles() {
      this.$axios.post('http://localhost:8080/car/all', {
        pageNum:1,
        pageSize:100,
        carTitle: this.bindVehicleDialog.searchPlate 
      })
      .then(resp => {
        if (resp.data.code === 200) {
          this.bindVehicleDialog.vehicleList = resp.data.data.records || [];
        }
      })
      .catch(error => {
        console.error('获取车辆列表失败', error);
      });
    },

    // 处理车辆选择变化
    handleVehicleSelectionChange(val) {
      this.bindVehicleDialog.selectedVehicle = val.length > 0 ? val[0] : null;
    },

    // 提交绑定车辆
    submitBindVehicle() {
      if (!this.bindVehicleDialog.selectedVehicle) {
        this.$message.error('请选择要绑定的车辆');
        return;
      }

      const params = {
        parkingId: this.bindVehicleDialog.form.parkingSpaceId,
        carId: this.bindVehicleDialog.selectedVehicle.carId
      };

      this.$axios.put('http://localhost:8080/parkingSpace/bcar', params)
        .then(resp => {
          if (resp.data.code === 200) {
            this.$message.success('车辆绑定成功');
            this.bindVehicleDialog.visible = false;
            this.getParkingSpace(this.currentPage);
          } else {
            this.$message.error(resp.data.message || '车辆绑定失败');
          }
        })
        .catch(error => {
          console.error('绑定车辆失败', error);
          this.$message.error('绑定失败，请重试');
        });
    },

    // 获取所有的收费标准
    getAllPricing() {
      this.$axios.get('http://localhost:8080/pricing/getpricebycommId', {
        params: {
          commId: this.chargeStandardForm.communityId,
        }
      }).then(resp => {
        if (resp.data.code === 200) {
          this.pricingList = resp.data.data || [];
        }
      }).catch(error => {
        console.error('获取收费标准失败:', error);
        this.$message.error('获取收费标准失败');
      });
    },
    // 添加收费标准
    addPricing(row) {
      console.log(row);
      this.currentParkingSpace = row; // 保存当前车位信息
      this.chargeStandardDialogVisible = true;
      this.chargeStandardForm.communityId = row.community.communityId; // 设置小区ID
      this.chargeStandardForm.parkingSpaceId = row.parkingSpaceId; // 设置车位ID
      this.getAllPricing();
    },
    // 收费标准选择变化
    handlePricingChange(pricingId) {
      const selectedPricing = this.pricingList.find(item => item.pricingId === pricingId);
      if (selectedPricing) {
        this.chargeStandardForm.pricingName = selectedPricing.pricingName;
      }
    },
    // 保存收费标准
    saveChargeStandard() {
      if (!this.chargeStandardForm.pricingId) {
        this.$message.warning('请选择收费标准');
        return;
      }
      const params = {
        parkingId: this.chargeStandardForm.parkingSpaceId,
        pricingId: this.chargeStandardForm.pricingId
      };
      this.$axios.put('http://localhost:8080/parkingSpace/bpricing', params)
        .then(response => {
          if (response.data.code === 200) {
            this.$message.success('收费标准设置成功');
            this.chargeStandardDialogVisible = false;
            // 刷新车位列表
            this.getParkingSpace(this.currentPage);
          } else {
            this.$message.error(response.data.message || '设置失败');
          }
        })
        .catch(error => {
          console.error('设置失败:', error);
          this.$message.error('设置失败');
        });
    },
  

    // 删除单个车位
    deleteParkingSpace(row) {
      this.selectedRows = [row.parkingSpaceId];
      this.deleteParkingSpaces();
    }
  }
};
</script>

<style scoped>
.parking-space-manage {
  padding: 20px;
}

.operation-buttons {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.search-area {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.dialog-footer {
  text-align: right;
}

.el-descriptions {
  margin-top: 20px;
}

.el-descriptions-item__label {
  font-weight: bold;
}
</style>